<template>
    <div class="login-wrap">
        <div class="login-container">
            <div class="header">后台管理系统</div>
            <div class="input-group">
                <el-input v-model="username" placeholder="请输入账号"></el-input>
                <el-input placeholder="请输入密码" v-model="password" show-password></el-input>
            </div>
            <div class="btn-group">
                <el-button type="primary" @click="login">登录</el-button>
            </div>
        </div>
    </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { useStore } from '@/store';
import { useRouter } from 'vue-router';
const username = ref('');
const password = ref('');
const store = useStore();
const router = useRouter();
const login = async () => {
  try {
    const res = await store.dispatch('Login', {
      username: username.value,
      password: password.value
    });
    if (res.data && res.data.token) {
      router.push('/');
    }
  } catch(err) {
    console.log(err);
  }
     
};
</script>
<style scoped lang='scss'>
  .login-wrap{
      width: 100vw;
      height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
      .header{
          text-align: center;
          font-size: 24px;
          font-weight: 800;
          color: $font-color-minor;
          margin-bottom: 50px;
      }
      .login-container{
          width: 400px;
          height: 400px;
          padding: 50px;
          padding: 50px;
          box-sizing: border-box;
          border: $border-style;
          .input-group{
              >.el-input{
                  margin-bottom: 40px;
              }
          }
          .btn-group{
              display: flex;
              justify-content: center;
              align-items: center;
              >.el-button{
                  width: 200px;
              }
          }
      }
  }
</style>
